package com.deyuanyun.pic.ctrl.controller.dto;

import java.math.BigDecimal;
import java.util.Date;

import com.alibaba.fastjson.annotation.JSONField;
import com.deyuanyun.pic.common.spring.SpringAppliction;
import com.deyuanyun.pic.common.util.StringUtils;
import com.deyuanyun.pic.common.util.poi.annotation.ExcelWriteColumn;
import com.deyuanyun.pic.common.util.web.Asserts;
import com.deyuanyun.pic.ctrl.enumeration.DefectStateEnum;
import com.deyuanyun.pic.ctrl.enumeration.RepairTaskStatedEnum;
import com.deyuanyun.pic.settings.controller.pipe.vo.PipeLocationDTO;
import com.deyuanyun.pic.settings.service.pipe.PipeLocationService;

/**
 * 维修项目前台需要的数据DTO。
 * 
 * @author ChenKui
 * @date 2016-06-20
 *
 */
public class RepairTaskDTO {

    private String repairTaskId;//维修任务编号
    @ExcelWriteColumn
    private String name;//维修任务名称
    
    private String pipeLineId;//管道编号
    @ExcelWriteColumn
    private String pipeLineName;//管道名称
    
    //private String pipeSegmentId;//管段编号
    //private String pipeSegmentName;//管段名称
    private String fromPointId;//起点编号
    private String toPointId;//终点编号
    
    @ExcelWriteColumn
    private String fromPointName;//起点名称
    @ExcelWriteColumn
    private String toPointName;//起点名称
    private BigDecimal fromPointMileage;//起点绝对距离
    private BigDecimal toPointMileage;//终点绝对距离

    public Long fromPointMileage2;//起点绝对距离
    public Long toPointMileage2;//终点绝对距离

    private DefectStateEnum dataState;//数据状态：已保存，发布
    private RepairTaskStatedEnum repairState;//修复状态枚举


    //--------------工作量---------------//
    public Long leakagePointWorkLoad;//腐蚀控制中_漏损点测量工作量

    @ExcelWriteColumn
    private String assemblyCompany;//施工单位
    @ExcelWriteColumn
    private Date planStartDate;//建议开工时间
    @ExcelWriteColumn
    private Date planCompletionDate;//建议竣工时间
    
    private Date releaseDate;//发布时间 
    
    private Date createDate;//创建时间
    
    @ExcelWriteColumn
    private String dataState_label;//枚举的返回中文（根据两个枚举值来判断过后的，因为前端是两个枚举的融合状态）

    public String getDataState_label() {
        if(dataState == DefectStateEnum.state20 ){//如果已发布了，就取修复状态
            if(repairState != null){//数据有可能没有状态
                dataState_label = repairState.getLabel();
            }
            
        }else{
            dataState_label = RepairTaskStatedEnum.valueOf(dataState.toString()).getLabel();
        }
        return dataState_label;
    }
    
    //获取起点位置名称
    public String getFromPointName() {
        if(StringUtils.isNotEmpty(fromPointName)){
            return fromPointName;
        }
        if(StringUtils.isEmpty(fromPointId)){
            return fromPointName;
        }
        PipeLocationService pipeLocationService = (PipeLocationService)SpringAppliction.getBean(PipeLocationService.class);
        PipeLocationDTO pipeLocation = pipeLocationService.queryPipeLocationById(pipeLineId,fromPointId);
        Asserts.assertTrue(pipeLocation != null, "没有找到起点编号对应的桩或者场站阀室、" + fromPointId);
        fromPointName = pipeLocation.getName();
        setFromPointMileage(pipeLocation.getMileage());
        setFromPointMileage2(pipeLocation.getMileage2());
        return fromPointName;
    }

    //获取终点位置名称
    public String getToPointName() {
        if(StringUtils.isNotEmpty(toPointName)){
            return toPointName;
        }
        if(StringUtils.isEmpty(toPointId)){
            return toPointName;
        }
        PipeLocationService pipeLocationService = (PipeLocationService)SpringAppliction.getBean(PipeLocationService.class);
        PipeLocationDTO pipeLocation = pipeLocationService.queryPipeLocationById(pipeLineId,toPointId);
        Asserts.assertTrue(pipeLocation != null, "没有找到终点编号对应的桩或者场站阀室、" + toPointId);
        toPointName = pipeLocation.getName();
        setToPointMileage(pipeLocation.getMileage());
        setToPointMileage2(pipeLocation.getMileage2());
        return toPointName;
    }

    //TODO 待验证：这个地方返回格式待处理。
    @JSONField(format="yyyy-MM-dd")
    public Date getPlanStartDate() {
        return planStartDate;
    }
    
    @JSONField(format="yyyy-MM-dd")
    public Date getPlanCompletionDate() {
        return planCompletionDate;
    }
    

    public BigDecimal getFromPointMileage() {
        getFromPointName();
        return fromPointMileage;
    }

    public BigDecimal getToPointMileage() {
        getToPointName();
        return toPointMileage;
    }

    public Long getFromPointMileage2() {
        if(fromPointMileage2 == null){
            getFromPointMileage();
        }
        return fromPointMileage2;
    }

    public Long getToPointMileage2() {
        if(toPointMileage2 == null){
            getToPointMileage();
        }
        return toPointMileage2;
    }

    //----------以下为自动生成-----------//
    
     
    
    public String getRepairTaskId() {
        return repairTaskId;
    }


    public void setFromPointMileage2(Long fromPointMileage2) {
        this.fromPointMileage2 = fromPointMileage2;
    }

    public void setToPointMileage2(Long toPointMileage2) {
        this.toPointMileage2 = toPointMileage2;
    }

    public void setFromPointMileage(BigDecimal fromPointMileage) {
        this.fromPointMileage = fromPointMileage;
    }

    public void setToPointMileage(BigDecimal toPointMileage) {
        this.toPointMileage = toPointMileage;
    }

    public Long getLeakagePointWorkLoad() {
        return leakagePointWorkLoad;
    }

    public void setLeakagePointWorkLoad(Long leakagePointWorkLoad) {
        this.leakagePointWorkLoad = leakagePointWorkLoad;
    }

    public String getFromPointId() {
        return fromPointId;
    }

    public String getToPointId() {
        return toPointId;
    }

    public void setFromPointId(String fromPointId) {
        this.fromPointId = fromPointId;
    }

    public void setToPointId(String toPointId) {
        this.toPointId = toPointId;
    }

    public Date getReleaseDate() {
        return releaseDate;
    }

    public void setReleaseDate(Date releaseDate) {
        this.releaseDate = releaseDate;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public RepairTaskStatedEnum getRepairState() {
        return repairState;
    }

    public void setRepairState(RepairTaskStatedEnum repairState) {
        this.repairState = repairState;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setRepairTaskId(String repairTaskId) {
        this.repairTaskId = repairTaskId;
    }
    
    public String getPipeLineId() {
        return pipeLineId;
    }
    public String getPipeLineName() {
        return pipeLineName;
    }
    public DefectStateEnum getDataState() {
        return dataState;
    }
    public String getAssemblyCompany() {
        return assemblyCompany;
    }
    
    public void setPipeLineId(String pipeLineId) {
        this.pipeLineId = pipeLineId;
    }
    public void setPipeLineName(String pipeLineName) {
        this.pipeLineName = pipeLineName;
    }
    public void setDataState(DefectStateEnum dataState) {
        this.dataState = dataState;
    }
    public void setAssemblyCompany(String assemblyCompany) {
        this.assemblyCompany = assemblyCompany;
    }
    public void setPlanStartDate(Date planStartDate) {
        this.planStartDate = planStartDate;
    }
    public void setPlanCompletionDate(Date planCompletionDate) {
        this.planCompletionDate = planCompletionDate;
    }

    
}
